Hi people,
actually im working on this code, i cant figure out why im getting that error when trying to feel a matrix with a function(just to have all the things separated), can any one explain me? i working to become better in C.
thank you in advice!!
BLESS, Ovnyx
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#define SHMEM_SIZE 1024
typedef struct{
char *name;
char board[6][6]; // * -> agua, M -> barco
int state; //1 con barco, 0 sin barco
int destroyed; //cant de barcos destruidos
}player;
void fill_board(player *Player){
for (size_t i = 0; i < 6; i++) {
for (size_t j = 0; i < 6; j++) {
Player->board[i][j] = '*';
}
}
}
void create_player(player *Player){
char x[20];
printf("Ingrese su nombre:\n");
scanf("%s", &x);
Player->name = x;
Player-> state = 0;
Player-> destroyed = 0;
fill_board(&(*Player));
/*
for (size_t i = 0; i < 6; i++) {
for (size_t j = 0; j < 6; j++) {
Player->board[i][j] = '*';
}
}
*/
}
int main(int argc, char *argv[]) {
player players[3];
create_player(&players[0]);
printf("Nombre: %s | Estado: %d | Barcos Destruidos: %d |\n", players[0].name, players[0].state, players[0].destroyed);
printf("\n");
for (size_t i = 0; i < 6; i++) {
for (size_t j = 0; j < 6; j++) {
printf("|%c",players[0].board[i][j]);
if (j == 5) {
printf("|%c|\n",players[0].board[i][j]);
}
}
}
printf("\n");
return 0;
}